﻿@{
    ViewBag.Title = "Tra cứu";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row-fluid">
    <div class="span12">
        <!-- BEGIN SAMPLE FORM PORTLET-->
        <div class="portlet box blue">
            <div class="portlet-title">
                <h4><i class="icon-reorder"></i>Thông tin tài chính</h4>
                <div class="tools">
                    <a href="javascript:;" class="collapse"></a>
                    <a href="#portlet-config" data-toggle="modal" class="config"></a>
                    <a href="javascript:;" class="reload"></a>
                    <a href="javascript:;" class="remove"></a>
                </div>
            </div>
            <div class="portlet-body form">
                <p>
                    @(Html.Kendo().AutoComplete()
                    .Name("TuKhoa")
                    .Filter("startswith")
                    .DataTextField("Text")
                    .Placeholder("Nhập từ khóa...")
                    .HtmlAttributes(new { style = "width: 200px" })
                            //.Template("${data.Text}")
                    .DataSource(source =>
                    {
                        source.Read(read =>
                        {
                            read.Action("TuKhoa", "TraCuu")
                                .Data("getTuKhoa");
                        })
                        .ServerFiltering(true);
                    })
                    .Events(e => {
                            e.Change("TuKhoa_Change");
                        })
                    
            )</p><p>

                    @(Html.Kendo().DropDownList()
                        .Name("ID_dt")
                        .OptionLabel("Chọn chuyên ngành")
                        .DataTextField("Text")
                        .DataValueField("Value")
                        .HtmlAttributes(new { style = "width:200px;" })
                        .DataSource(source =>
                        {
                            source.Read(read =>
                            {
                                read.Action("getChuyenNganh", "TraCuu")
                                    .Data("getTuKhoa")
                                    ;
                            })
                            .ServerFiltering(true)
                            ;
                        })
                            //.Enable(false)
                        .AutoBind(false)
                        .Events(e => {
                            e.DataBound("ID_dt_DataBound");
                        })
                            //.CascadeFrom("TuKhoa")
                    )

                    @(Html.Kendo().DropDownList()
    .Name("NamHoc")
    .OptionLabel("Toàn khóa")
    .HtmlAttributes(new { style = "width:120px" })
    .DataTextField("Text")
    .DataValueField("Value")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("NamThu", "TraCuu")
                .Data("getTuKhoa");
        })
        .ServerFiltering(true);
    })
                            //.Enable(false)
    .AutoBind(false)
    .CascadeFrom("ID_dt")
)

                    @(Html.Kendo().DropDownList()
    .Name("HocKy")
    .HtmlAttributes(new { style = "width:120px" })
    .OptionLabel("Cả năm")
    .DataTextField("Text")
    .DataValueField("Value")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("KyThu", "TraCuu")
                .Data("getTuKhoa");
        }).ServerFiltering(true);
    })
    .Enable(false)
    .AutoBind(false)
        .CascadeFrom("NamHoc")
)
                    @(Html.Kendo().DropDownList()
    .Name("DotThu")
    .HtmlAttributes(new { style = "width:120px" })
    .OptionLabel("Đợt thu")
    .DataTextField("Text")
    .DataValueField("Value")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("DotThu", "TraCuu")
                .Data("getTuKhoa");
        }).ServerFiltering(true);
    })
    .Enable(false)
    .AutoBind(false)
        .CascadeFrom("HocKy")
)
                    @(Html.Kendo().DropDownList()
    .Name("LanThu")
    .HtmlAttributes(new { style = "width:120px" })
    .OptionLabel("Lần thu")
    .DataTextField("Text")
    .DataValueField("Value")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("LanThu", "TraCuu")
                .Data("getTuKhoa");
        }).ServerFiltering(true);
    })
    .Enable(false)
    .AutoBind(false)
        .CascadeFrom("DotThu")
)


                    <button class="k-button" id="TraCuuButton">Tra cứu</button>
                </p>
                @(Html.Kendo().Grid<StudentPortal.ViewModels.BienLaiThu>()
    .Name("GridBienLai")
    .Columns(columns =>
    {
        columns.Bound(t => t.Noi_dung).Width(150);
        columns.Bound(t => t.So_tien).Width(50).Format("{0:C}");
        columns.Bound(t => t.Ngay_thu).Width(50).Format("{0:dd/MM/yyyy}");
        columns.Bound(t => t.Nguoi_thu).Width(50);
        columns.Bound(t => t.Nam_hoc).Hidden();
        columns.Bound(t => t.Hoc_ky).Hidden();
        columns.Bound(t => t.Dot_thu).Hidden();
        columns.Template(@<text></text>).ClientTemplate("<div class='changeRowColor' Chua_dong='#=Chua_dong#'").Hidden();
    })
    .Groupable()
    .Pageable()
    .Sortable()
    .Selectable()
    .Pageable(pager => pager.Enabled(false))
    .DataSource(
        dataSource => dataSource.Ajax()
                .Group(group => group.Add(t => t.Nam_hoc))
                .Group(group => group.Add(t => t.Hoc_ky))
                .Group(group => group.Add(t => t.Dot_thu))
                .Group(group => group.Add(t => t.Ten_lan))
            .Read(read => read.Action("BienLaiThu", "TraCuu").Data("getTuKhoa"))
    )
    .Events(e => {
        e.DataBound("GridBienLai_DataBound");
    })
    .HtmlAttributes(new { style = "min-height:400px" })
)
            </div>
        </div>
    </div>
</div>
@if(ViewBag.IsSinhVien){
        <div id="SinhVien" Ma_sv ="@User.Identity.Name"></div>
    }
<style>
    .chua_dong {
        background-color:#F2DEDE;
        border: 1px solid;
        /*color: #fff;*/
    }
</style>
<script type="text/javascript">
    $(document).ready(function () {
        $('#SinhVien').each(function () {
            $('#TuKhoa').val($(this).attr('Ma_sv'));

        });
    });
    function TuKhoa_Change() {
        $('#ID_dt').data('kendoDropDownList').dataSource.read();
    }
    function GridBienLai_DataBound() {
        $('.changeRowColor').each(function () {
            if ($(this).attr('Chua_dong') == 'true') {
                $(this).parent().parent().addClass('chua_dong');
            }
        });
    }
    function getTuKhoa() {
        return {
            ID_dt: $('#ID_dt').val(),
            TuKhoa: $("#TuKhoa").val(),
            NamHoc: $("#NamHoc").val(),
            HocKy: $("#HocKy").val(),
            DotThu: $("#DotThu").val(),
            LanThu: $("#LanThu").val()
        };
    }
    function ID_dt_DataBound() {
        var t = $('#ID_dt').data('kendoDropDownList');
        t.value(t.dataSource._data[0].Value);
    }
    $("#TraCuuButton").click(function () {
        $("#GridBienLai").data("kendoGrid").dataSource.read();
    });
</script>
